package com.future.controller;

import com.future.pojo.*;
import com.future.service.MusicService;
import com.future.service.SingerService;
import com.future.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class RouteConreoller {

    private final SingerService singerService;
//    @Autowired
//    private SingerMapper singerMapper;

    private final MusicService musicService;

    private final UserService userService;

    public RouteConreoller(SingerService singerService,
                           MusicService musicService,
                           UserService userService) {
        this.singerService = singerService;
        this.musicService = musicService;
        this.userService = userService;
    }


    @ApiOperation(value = "首页")
    @RequestMapping("/")
    public String welcome(Model model,HttpSession session) {
        Users user;
        if(session.getAttribute("User")!=null){
            user = (Users) session.getAttribute("User");
        }else if(session.getAttribute("USer")!=null){
            user = (Users) session.getAttribute("USer");
        }else{
            user = (Users) session.getAttribute("user");
        }
        session.setAttribute("USER",user);
        System.out.println(user);
        //歌手推荐
        List<Users> list = singerService.querySixSinger();
        model.addAttribute("Singer", list);

        //热歌榜
        List<Musics> hot = musicService.HotFiveMusic();
        model.addAttribute("Musics1", hot);

        //新歌榜
        List<Musics> newe = musicService.NewFiveMusic();
        model.addAttribute("Musics2", newe);

        //翻唱榜
        List<Musics> fan = musicService.FanFiveMusic();
        model.addAttribute("Musics3", fan);

        //欧美榜
        List<Musics> engi = musicService.EngliFiveMusic();
        model.addAttribute("Musics4", engi);

        //日韩榜
        List<Musics> rifv = musicService.RiFiveMusic();
        model.addAttribute("Musics5", rifv);

        //每日推荐
        List<Album> tui = musicService.TuiFiveAlbum();
        model.addAttribute("Album1", tui);

        //RAP榜
        List<Album> rr = musicService.RapFiveAlbum();
        model.addAttribute("Album2", rr);

        //POP流行榜
        List<Album> re = musicService.PopFiveAlbum();
        model.addAttribute("Album3", re);

        //FOLK民谣榜
        List<Album> uy = musicService.FolkFiveAlbum();
        model.addAttribute("Album4", uy);

        //SOUNDTRACK影视原声榜
        List<Album> uo = musicService.SoundtrackFiveAlbum();
        model.addAttribute("Album5", uo);

        //ROCK摇滚榜
        List<Album> oo = musicService.RockFiveAlbum();
        model.addAttribute("Album6", oo);
        return "L-html/L-homepage/L-findMusic";
    }


    @ApiOperation(value = "跳转到VIP界面")
    @GetMapping("/toVIPpaper")                           //测试通过
    public String toVIPpaper() {
        return "/L-html/L-homepage/L-vip.html";
    }


    @ApiOperation(value = "跳转到个人中心界面")
//    查询我喜欢 我的下载 个人信息
    @GetMapping("/toMyMusicpaper")                           //测试通过
    public String tomyMusicpaper(HttpSession session, Model model) {
        //我下载的歌曲
        Users user = (Users)session.getAttribute("USER");

        //查询我的歌单
        List<Musiclist> musiclists = musicService.userMusiclist(user.getUserId());

        List<Musiclistmusic> Down = musicService.queryOneDownmclist(user.getUserId());
        //我喜欢的歌曲
        List<Musiclistmusic> Love = musicService.queryOneLovemclist(user.getUserId());
        //查找个人信息
        List<Users> users = userService.queryByIdUser(user.getUserId());
        //传到前端界面
        model.addAttribute("Down", Down);
        model.addAttribute("Love", Love);
        model.addAttribute("Users", users);
        model.addAttribute("list", musiclists);
        return "/L-html/L-homepage/L-personCenter.html";
    }

    @ApiOperation(value = "跳转到Mv界面")
    @GetMapping("/toMvpaper")                           //测试通过
    public String toMvpaper() {
        return "/L-html/L-homepage/L-mv.html";
    }


    @ApiOperation(value = "跳转到Mv")
    @GetMapping("/toMv")                           //测试通过
    public String toMv() {
        return "/ypb/Y-html/Y-item/video.html";
    }


    @ApiOperation(value = "登录页面")
    @RequestMapping("/loginpage")
    public String loginpage(Model model) {

        return "/ypb/Y-enter/register/enter.html";
    }

    @RequestMapping("/out")
    public void signout(HttpSession session, HttpServletResponse response) throws Exception{
        session.removeAttribute("User");
        session.removeAttribute("USer");
        session.removeAttribute("user");
        session.removeAttribute("USER");
        response.sendRedirect("/future/");
    }

    @RequestMapping("/homepage")
    public String homepage(Model model) {

        return "/ypb/Y-background/user.html";
    }

    @GetMapping("/gitee")
    @ResponseBody
    public Judge giteelogin(HttpSession session){
        Judge judge = new Judge();
        if(session.getAttribute("USER")!=null){
            judge.setStatusCode(1);
        }else{
            judge.setStatusCode(0);
        }
        return judge;
    }
    @RequestMapping("/BindCount")
    public String bindCount(){
        return "/ypb/Y-enter/register/bind.html";
    }
}
